﻿using UnityEngine.UIElements;

namespace winS.UnityEditor.UIElement
{
    public class FloatField : EditorField<float>
    {
        public VisualElement inputField => floatField;
        public VisualElement inputElement=> floatField.Q("unity-text-input");

        private readonly UnityEngine.UIElements.FloatField floatField;

        internal FloatField(ElementFactory elementFactory) : base(elementFactory)
        {
            Add(floatField = new UnityEngine.UIElements.FloatField());
            EditorElementUtility.ApplySubFieldStyle(floatField);
            floatField.RegisterValueChangedCallback(OnValueChangedCallback);
        }

        public override void SetValueWithoutNotify(float value)
        {
            base.SetValueWithoutNotify(value);
            floatField.SetValueWithoutNotify(value);
        }

        protected override void SetValue(float value)
        {
            base.SetValue(value);
            floatField.SetValueWithoutNotify(value);
        }

        private void OnValueChangedCallback(ChangeEvent<float> changeEvent)
        {
            base.SetValue(changeEvent.newValue);
        }
    }
}